package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntHardwareAsset;
import com.nt.oam.service.IAntHardwareAssetService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 硬件资产Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/hardware")
public class AntHardwareAssetController extends BaseController {
    @Autowired
    private IAntHardwareAssetService antHardwareAssetService;

    /**
     * 查询硬件资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntHardwareAsset antHardwareAsset) {
        startPage();
        List<AntHardwareAsset> list = antHardwareAssetService.selectAntHardwareAssetList(antHardwareAsset);
        return getDataTable(list);
    }

    /**
     * 导出硬件资产列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:export')")
    @Log(title = "硬件资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntHardwareAsset antHardwareAsset) {
        List<AntHardwareAsset> list = antHardwareAssetService.selectAntHardwareAssetList(antHardwareAsset);
        ExcelUtil<AntHardwareAsset> util = new ExcelUtil<AntHardwareAsset>(AntHardwareAsset.class);
        util.exportExcel(response, list, "硬件资产数据");
    }

    /**
     * 获取硬件资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:query')")
    @GetMapping(value = "/{hardwareAssetId}")
    public AjaxResult getInfo(@PathVariable("hardwareAssetId") Long hardwareAssetId) {
        return success(antHardwareAssetService.selectAntHardwareAssetByHardwareAssetId(hardwareAssetId));
    }

    /**
     * 新增硬件资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:add')")
    @Log(title = "硬件资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntHardwareAsset antHardwareAsset) {
        return toAjax(antHardwareAssetService.insertAntHardwareAsset(antHardwareAsset));
    }

    /**
     * 修改硬件资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:edit')")
    @Log(title = "硬件资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntHardwareAsset antHardwareAsset) {
        return toAjax(antHardwareAssetService.updateAntHardwareAsset(antHardwareAsset));
    }

    /**
     * 删除硬件资产
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:remove')")
    @Log(title = "硬件资产", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hardwareAssetIds}")
    public AjaxResult remove(@PathVariable Long[] hardwareAssetIds) {
        return toAjax(antHardwareAssetService.deleteAntHardwareAssetByHardwareAssetIds(hardwareAssetIds));
    }


    /**
     * 非系统----获取硬件资产详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:query')")
    @GetMapping(value = "/details/{hardwareAssetId}")
    public AjaxResult getHardwareAssetMessage(@PathVariable("hardwareAssetId") Long hardwareAssetId) {
        return success(antHardwareAssetService.selectAntHardwareAssetByHardwareAssetId(hardwareAssetId));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getHardwareModify(@RequestParam Long hardwareAssetId) {
        return success(antHardwareAssetService.selectHardwareModify(hardwareAssetId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:hardware:edit')")
    @Log(title = "硬件资产", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{hardwareAssetId}")
    public AjaxResult editModify(@PathVariable("hardwareAssetId") Long hardwareAssetId) {
        int isModify = 1;
        return toAjax(antHardwareAssetService.updateHardwareModify(hardwareAssetId,isModify));
    }
}
